export default (Vue) => {
  
  //对象复制
  Vue.prototype.cloneObj = (obj) => {
    return JSON.parse(JSON.stringify(obj))
  }
  //cookie的写入与修改

  //获取cookie
  Vue.prototype.getCookie = (name) => {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
      return (arr[2]);
    else
      return null;
  }

  //设置cookie
  Vue.prototype.setCookie = (c_name, value, expiredays) => {
    var exdate = new Date();
    exdate = new Date(exdate.getTime() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());

  };

  //删除cookie
  Vue.prototype.delCookie = (name) => {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = Vue.prototype.getCookie(name);
    if (cval != null)
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  };

  //过滤器保留几位小数
  Vue.filter('toFixed', (value, num) => {
    if (value) {
      return Number(value).toFixed(num)
    } else {
      return null
    }
  });

  //获取当前时间
  Vue.prototype.getnowDate = (data) => {
    var myDate = new Date();
    var year = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
    var month = myDate.getMonth() + 1;       //获取当前月份(1-12)
    var day = myDate.getDate();        //获取当前日(1-31)
    //获取完整年月日
    return year + "/" + month + "/" + day;
  };

  // 打开word文档
  Vue.prototype.openWord = (downloadID, path) =>{
    let doad = document.getElementById(downloadID);
    doad.href = "http://view.officeapps.live.com/op/view.aspx?src=" + path;
  };

}